//
//  Topic.swift
//  VO_Yuejie
//
//  Created by laichunhui on 15/11/17.
//  Copyright © 2015年 lch. All rights reserved.
// 主题

import UIKit

class Topic: NSObject {
    
    /// 创建时间
    var created_at: String?
    /// 发布时间
    var publish_at: String?
    
    /// ID
    var id: Int = 0
    /// 主题配图地址
    var image_url: String?
    
    /// 主题标题
    var title: String?
    
    /// valueObject
    var value_object: ValueObject?
    
    /// 加载主题详情value
    var value: String?
    /// 主题包内容下载地址
    var package_url: String?
    
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        // 1. 判断 key 是否是 "User"
        if key == "value_object" {
            // 如果 key 是 user, value 是字典
            // 调用 User 的构造函数创建 user 对象属性
            value_object = ValueObject(dict: value as! [String: AnyObject])
            // 如果不return，user 属性又会被默认的 KVC 方法，设置成字典
            return
        }
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        let keys = ["created_at", "id", "image_url", "title", "value_object", "package_url"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
    
}

